package psnl.bingo.mr.demo4;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

public class D4Mapper extends Mapper<LongWritable, Text, D4Line, NullWritable> {
    D4Line outKey = new D4Line();

    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        // 行数据字符转对象
        String lineStr = value.toString();
        String[] item = lineStr.split(";");

        outKey.setCity(item[0]);
        outKey.setObj(item[1]);
        outKey.setMonth(item[2].substring(0, 6));
        outKey.setData(Integer.parseInt(item[3]));

        context.write(outKey, NullWritable.get());
    }
}
